package itbour.onetouchshow.fragment.me;

import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.App;
import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.DeviceUtil;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;
import itbour.onetouchshow.utils.UIUtils;

/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class MePresenter extends BasePresenterImpl<MeContract.View> implements MeContract.Presenter {

    /**
     * 用户中心作品数据
     */
    public void loadPersonalCenterInfo() {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("opTypes", "[2,4]");
        //pageNum	是
        stringObjectHashMap.put("pageNum", 0);
        //页码 pageSize
        stringObjectHashMap.put("pageSize", 4);
        //getUserWorkListForWeb_v1_0
        HttpUtils.getInstance().executeGet(AppConfig.GETUSERWORKLIST_V1_0, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                mvpView.loadFaild(exception);
            }

            @Override
            protected void onSuccess(String response) {
                L_.e(response);
                L_.e("我的作品列表" + response);
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });
    }

    public void loadUserDetailInfo() {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        HttpUtils.getInstance().executeGet(AppConfig.GETUSERDETAILINFO_V1_0, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                T_.showCustomToast(exception);
            }

            @Override
            protected void onSuccess(String response) {
                // SpUtils.getInstance().saveString(AppConst.USER_INFO, response);
                mvpView.loaduserDetailSuccess(response);
            }
        });
    }


    /**
     * 作品预览  new
     */
    public void newLoadDocPreview(String docId) {
        L_.e("作品预览" + docId);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        HttpUtils.getInstance().executePost(AppConfig.REQUESTUSERDOCPRIVEWINFO_WEB_V1_1, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showCustomToast(exception);
                L_.e("newLoadDocPreview" + exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                if (mvpView != null) {
                    L_.e("newLoadDocPreview" + response);
                    mvpView.loadNewDocPreviewSuccess(response);
                }
            }
        });
    }


    public void getVipPageInfo() {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        String appVersionName = DeviceUtil.getAppVersionName(UIUtils.getContext());
        stringObjectHashMap.put("appVer", appVersionName);
        HttpUtils.getInstance().executeGet(AppConfig.GET_VIP_PAGE_INFO, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                T_.showCustomToast(exception);
                mvpView.loadVipInfoFail();
            }

            @Override
            protected void onSuccess(String response) {
                mvpView.loadVipInfoSuccess(response);
            }
        });
    }


//    /**
//     * 获取自由创建配置项
//     */
//
//    public void getCustomVideoConfigure(String docId) {
//        HashMap<String, String> stringStringHashMap = new HashMap<>();
//        stringStringHashMap.put("device", 2 + "");
//        stringStringHashMap.put("appVer", "3.0.0");
//        HttpUtils.getInstance().executeGet(AppConfig.GETCUSTOMVIDEOCONFIGURE_APP_V3_0, stringStringHashMap, new EncryBeanCallBack() {
//            @Override
//            protected void onXError(String exception) {
//                T_.showCustomToast(exception);
//                mvpView.loadFaild(exception);
//            }
//
//            @Override
//            protected void onSuccess(String response) {
//                mvpView.getCustomVideoConfigureResutl(response,docId);
//            }
//        });
//
//    }


    /**
     * 获取自由创建数据
     */
    public void getCustomVideodoccontent(String docId) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("docId", docId);
        HttpUtils.getInstance().executeGet(AppConfig.CUSTOMVIDEODOCCONTENT, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                //T_.showToastReal(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                //T_.showToastReal(response);
                if (mvpView != null) {
                    mvpView.getCustomVideodoccontentResult(response);
                }

                L_.e(response);
            }
        });

    }


    /**
     * 获取作品数据
     */
    public void getDocString(String docId) {
        HashMap<String, Object> stringStringHashMap = new HashMap<>();
        //  L_.e(videoBean.getId() + "");
        stringStringHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringStringHashMap.put("id", docId);
        stringStringHashMap.put("userId", App.getUserId());
        stringStringHashMap.put("isTmpl", 0);
        HttpUtils.getInstance().executeGet(AppConfig.GET_DOC_CONTENT_V10, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                L_.e(exception);
                T_.showToastReal(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {

                if (mvpView != null) {
                    mvpView.getDocStringPreview(response);
                }

            }
        });

    }


}
